package HomeWork.collection;

import java.util.*;

public class DouDiZhu {
    private static final String[] COLORS = {"♣","♦", "♥", "♠"};

    public static void main(String[] args) {
        String[] porkers = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
        ArrayList<String> list = new ArrayList<>();
        for (String porker : porkers) {
            for (String color : COLORS) {
                list.add(porker + color);
            }
        }
        list.add("小王");
        list.add("大王");
        Collections.shuffle(list);
        ArrayList<String> user1 = new ArrayList<>(list.subList(0, 17));
        ArrayList<String> user2 = new ArrayList<>(list.subList(17, 34));
        ArrayList<String> user3 = new ArrayList<>(list.subList(34, 51));
        ArrayList<String> hiddenCards = new ArrayList<>(list.subList(51, 54));
        user1.sort(getComparator());
        user2.sort(getComparator());
        user3.sort(getComparator());
        hiddenCards.sort(getComparator());
        System.out.println("朱旭" + user1);
        System.out.println("蔡春林" + user2);
        System.out.println("邓旭" + user3);
        System.out.println("底牌" + hiddenCards);
    }

    private static Comparator<String> getComparator() {
        return (o1, o2) -> {
            ArrayList<String> compare = new ArrayList<>(List.of("3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "小", "大"));
            List<String> colors = Arrays.stream(COLORS).toList();
            int result = compare.indexOf(o2.substring(0, o2.length() - 1)) - compare.indexOf(o1.substring(0, o1.length() - 1));
            result = result == 0 ? colors.indexOf(o2.substring(o2.length() - 1)) - colors.indexOf(o1.substring(o1.length() - 1)) : result;
            return result;
        };
    }
}
